package data.xml;

import data.component.Wall;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 复合特征点 用于xml墙面分割
 */
public class MixPoint implements Comparable<MixPoint>
{
    public String pointType;
    public Double[] coordinate;
    public MixPoint next;
    public Double sum;

    public MixPoint(String pointType, Double[] coordinate, MixPoint next)
    {
        this.coordinate = coordinate;
        this.pointType = pointType;
        this.next = next;
        this.sum = coordinate[0] + coordinate[1];
    }

    public static List<MixPoint> SortMixPointsByWall(Wall wall)
    {
        var mixPoints = new ArrayList<MixPoint>();

        mixPoints.add(new MixPoint("WallStart", wall.start, null));
        mixPoints.add(new MixPoint("WallEnd", wall.end, null));
        for (var op : wall.openings)
        {
            mixPoints.add(new MixPoint("OpeningStart", op.start, null));
            mixPoints.add(new MixPoint("OpeningEnd", op.end, null));
        }

        Collections.sort(mixPoints);
        for (int i = 0; i < mixPoints.size(); i++)
        {
            if (i != mixPoints.size() - 1)
                mixPoints.get(i).next = mixPoints.get(i + 1);
        }

        return mixPoints;
    }


    public int compareTo(MixPoint p)
    {
        var value =new Double (this.sum - p.sum);

        return value.intValue();
    }
}
